﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace FTchina.Api
{
    /// <summary>
    ///pinglun 的摘要说明
    /// </summary>
    public class pinglun
    {
        public pinglun()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        /// <summary>
        /// 获取评论条目
        /// </summary>
        /// <param name="list">指定条目数</param>
        /// <param name="number">每行显示字符数</param>
        /// <param name="laststr">最后的字符，如……</param>
        /// <returns></returns>
        public static string GetList(int list, int number, string laststr)
        {
            if (FTchina.Caching.FTchinaCache.IsExits("GetpinglunList"+list + number + laststr))
            {
                return FTchina.Caching.FTchinaCache.GetCache("GetpinglunList" + list + number + laststr);
            }
            else
            {
            string tempwords = string.Empty;
            DataTable dt = shujuku.GetDataTable("select top " + list + " * from pinglun where ispass='已审核' order by id desc", "GetList");
            tempwords += "<ul class='nl'>";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                tempwords += "<li><a href=\"s" + dt.Rows[i]["artid"] + ".aspx#" + dt.Rows[i]["id"].ToString() + "\"  target=\"_blank\" >" + basic.GetSubString(dt.Rows[i]["pinglun"].ToString(), number, laststr) + "</a></li>";
            }
            tempwords += "</ul>";
            FTchina.Caching.FTchinaCache.AddCache("GetpinglunList" + list + number + laststr, tempwords);
            return tempwords;
            }
        }

        /// <summary>
        /// 获取指定文章的评论
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string GetPinglun(string id)
        {
            if (FTchina.Caching.FTchinaCache.IsExits("GetPinglun" + id ))
            {
                return FTchina.Caching.FTchinaCache.GetCache("GetPinglun" + id);
            }
            else
            {
            string sql = "select * from pinglun where artid='" + id + "' and ispass='已审核' order by id desc";
            DataTable dt = shujuku.GetDataTable(sql, "GetPinglun");
            string tempwords = "";
            int j = dt.Rows.Count;
            for (int i = 0; i < dt.Rows.Count; i++)
            {

                tempwords += "<div class='reHead'><div class='reLayer'><a name=" + dt.Rows[i]["id"] + ">  </a>第 " + j + " 楼</div>";
                j--;
                tempwords += "<span class='reName'>" + dt.Rows[i]["ip"].ToString() + "<img src='"+basic.GetSiteMainWorkUrl()+"pic/member_male.gif' /></span> 发表于<span class='reDate'>" + dt.Rows[i]["time"].ToString() + "</span></div><div class='reBody'>" + dt.Rows[i]["pinglun"].ToString() + "</div>";

            }
               FTchina.Caching.FTchinaCache.AddCache("GetPinglun" + id, tempwords);
            return tempwords;
            }
        }

    }
}